package com.turtle3d.user.grammars;

import java.util.ArrayList;

import com.turtle3d.formallanguage.grammar.Grammar;
import com.turtle3d.formallanguage.parser.SimpleParser;
import com.turtle3d.formallanguage.symbol.Method;
import com.turtle3d.formallanguage.symbol.Symbol;
import com.turtle3d.formallanguage.symbol.SymbolFactory;

public class Sponge extends Grammar {

	@Override
	public void define() {

		String window = "[B]f[B]f[B]+f[B]f[B]+f[B]f[B]+f[B]f";
		String positionInCorner = "\\f(0.33)/++f(0.33)+f(0.33)+";
		String right = positionInCorner+"S[B]f[B]f[B][/f\\[B]]+f[B]f[B][/f\\[B]]+f[B]f[B][/f\\[B]]+f[B]f+/f[B]f\\"+window;				

		SymbolFactory.getSymbolFactory().registerSymbolClass("f", "f(0.33)",
				new Method() {
					public boolean calculate(ArrayList<Symbol> symbolSequence, int symbolIndex, Symbol calculatedSymbol) {
						calculatedSymbol.setParameter(Symbol.DISTANCE, calculatedSymbol.getParameter(Symbol.DISTANCE)*0.3333333f);
						return true;
					}
				});

		setAxiom(SymbolFactory.getSymbolFactory().createSymbolofClass("B"));
		addProduction(SimpleParser.parseProduction("B->" + right));

	}

	@Override
	public void setRequiredParameters() {
		setRequiredParameter(Symbol.TURN_ANGLE, 90f);
		setRequiredParameter(Symbol.PITCH_ANGLE, 90f);
		setRequiredParameter(Symbol.DISTANCE, 2f);
		setRequiredParameter(Symbol.SCALE_MULTIPLIER, 0.33333f);
	}

}
